<template>
  <el-dialog
    class="batchModify"
    destroy-on-close
    center
    v-model="visible"
    :title="dialogDatas.title"
    width="40%"
    @closed="onReset"
  >
    <el-form :model="dialogDatas" ref="formRef" class="px12">
      <el-form-item label="修改机构归属为" prop="dialogDatas.name">
        <!-- <el-input v-model="dialogDatas.name" clearable /> -->
        <el-select v-model="dialogDatas.value">
          <el-option
            :label="option.name"
            :value="option.id"
            v-for="option in dialogDatas.options()"
            :key="option.id"
          />
        </el-select>
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="visible = false">取消</el-button>
        <el-button type="primary" @click="onConfirm">确认</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script lang="ts" setup>
import { ref, reactive, nextTick } from 'vue';
import type { FormInstance } from 'element-plus';
import type { IRoleItem } from '@/api/role/type';
import { batchChangeOwner } from '@/api/checkPointEquipment';

const emits = defineEmits(['onConfirm']);

const visible = ref(false);
const formRef = ref<FormInstance>();
const dialogDatas = reactive({});

const init = async (data?: IRoleItem) => {
  visible.value = true;
  if (data) {
    // await nextTick();
    Object.assign(dialogDatas, data);
  }
};
const onReset = () => {
  if (!formRef.value) return;
  formRef.value.resetFields();
};

const onConfirm = async() => {
  const datas = {
    ids: dialogDatas.multipleSelection,
    orgId: dialogDatas.value
  };
const data:any= await batchChangeOwner(datas);
if (data.code === 2000) {
  ElMessage.success('批量修改成功');
}

  visible.value = false;
  emits('onConfirm');
};
const getBatchChangeOwnerDatas = async (data: {}) => {
  await batchChangeOwner(data);
};
defineExpose({ init });
</script>

<style lang="scss">
.batchModify {
  .el-form-item {
    display: inline-block;
  }
  .el-form-item__content {
    width: 200px;
  }
}
</style>
